#ifndef NIXONBOT_CORE_BNCS_PROTOCOL_PING_H_
#define NIXONBOT_CORE_BNCS_PROTOCOL_PING_H_

#include <nixonbot/core/bncs/protocol/Message.h>
#include <nixonbot/core/bncs/protocol/MessageFactory.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

struct PingData : public QSharedData
{
	quint32 data;
};

class Ping : public Message
{
public:
	static const int id = 0x25;
	BNCS_MESSAGE_CLIENT_REGISTER(Ping, id);
	BNCS_MESSAGE_SERVER_REGISTER(Ping, id);

public:
	QSharedDataPointer<PingData> d;

public:
	Ping()
	{
		d = new PingData();
	}
	
	virtual Ping* create()
	{
		return new Ping();
	}

	virtual int id()
	{
		return id;
	}

	virtual int size()
	{
		return sizeof(d->data);
	}

protected:
	virtual void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds >> d->data;

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	virtual void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds << d->data;

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

}
}
}
}

#endif /* NIXONBOT_CORE_BNCS_PROTOCOL_PING_H_ */
